﻿using Digitalmes.Application.Sys.Menus;
using Digitalmes.Application.Sys.Users.Services;

namespace Digitalmes.Application.Sys.Users.Queries;

/// <summary>
/// 查询用户拥有的菜单命令。
/// </summary>
/// <param name="UserId"></param>
public record GetMenusOfUserQuery(long UserId) : IRequest<IResult<List<SysMenuDto>>>;

internal sealed class GetMenusOfUserQueryHandler(IUserMenuApplicationService service) : IRequestHandler<GetMenusOfUserQuery, IResult<List<SysMenuDto>>>
{
    public async Task<IResult<List<SysMenuDto>>> Handle(GetMenusOfUserQuery request, CancellationToken cancellationToken)
    {
        var menus = await service.GetMenuListByUserIdAsync(request.UserId);
        return Result.From(menus);
    }
}
